<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<table class="display" id="example">
    <thead>
    <tr>
        <th>选择</th>
        <th>姓名</th>
        <th>面试岗位</th>
        <th>报到单位</th>
        <th>面试时间</th>
        <th>到岗时间</th>
        <th>状态</th>
        <th>合同状态</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.interviewArrangePOJOs==null || #request.interviewArrangePOJOs.size() <= 0">
        <tr class="gradeA">
            <td colspan="8">暂无招聘数据</td>
        </tr>
    </s:if>
    <s:else>
        <s:iterator value="#request.interviewArrangePOJOs" var="interview" status="sta">
            <s:if test="#sta.even">
                <tr class="gradeA">
            </s:if>
            <s:else>
                <tr class="gradeC">
            </s:else>

            <td><input type="checkbox" name="chk_interview_arrange" value="${interview.id}"/></td>
            <td>${interview.name}</td>
            <td>${interview.dutyName}</td>
            <td>${interview.organization.path}</td>
            <td><s:if test="#interview.interviewTime == null">未开始</s:if><s:else>
                <fmt:formatDate value="${interview.interviewTime}" pattern="yyyy-MM-dd"></fmt:formatDate>
            </s:else>
            </td>
            <td><s:if test="#interview.interviewTime == null">未报到</s:if><s:else>
                <fmt:formatDate value="${interview.reportTime}" pattern="yyyy-MM-dd"></fmt:formatDate>
            </s:else>
            </td>
            <td>
                <s:if test="#interview.status == null || #interview.status.toString()== 'uncheck_in'">
                    <a href="javascript:void(0)" id="simple-button${interview.id}" value="Simple Popover"
                       class="button"><span class="icon"
                                            style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>未到</a>

                    <div id="simple-popover${interview.id}" class="popover">
                        <header> 报到状态</header>
                        <section>
                            <div class="content">
                                <nav>
                                    <ul>
                                        <li class="read"><a><span class="avatar"></span>
                                            <input type="radio" name="checkin_rd${interview.id}" value="give_up"/>
                                            放弃
                                            <input type="radio" name="checkin_rd${interview.id}" value="check_in"/>
                                            已报到
                                        </a><a href="javascript:void(0)" class="button"
                                               onclick="modifyInterviewCheckState(${interview.id},${interview.employeeId})"><span class="icon"
                                                                                                          style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定</a><a> </a>
                                        </li>
                                    </ul>
                                </nav>
                            </div>
                        </section>
                    </div>
                    <script>
                        $(document).ready(function () {
                            $('#simple-button${interview.id}').popover('#simple-popover${interview.id}', {});
                            $('#top-button').popover('#top-popover', {preventLeft:true, preventRight:true, preventBottom:true});
                        });
                    </script>
                </s:if>
                <s:elseif test="#interview.status.toString() == 'give_up'">
                    <a href="javascript:void(0)" id="simple-button${interview.id}" value="Simple Popover"
                       class="button"><span class="icon"
                                            style="background:url(${ctx}/images/img/delete.png)">&nbsp;</span>${interview.status.name}
                    </a>

                    <div id="simple-popover${interview.id}" class="popover">
                        <header> 报到状态</header>
                        <section>
                            <div class="content">
                                <nav>
                                    <ul>
                                        <li class="read"><a><span class="avatar"></span>
                                            <input type="radio" value="uncheck_in" name="checkin_rd${interview.id}"/>
                                            重新报到
                                        </a><a href="javascript:void(0)" class="button"
                                               onclick="modifyInterviewCheckState(${interview.id},${interview.employeeId})"><span class="icon"
                                                                                                          style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>确定</a><a> </a>
                                        </li>
                                    </ul>
                                </nav>
                            </div>
                        </section>
                    </div>
                    <script>
                        $(document).ready(function () {
                            $('#simple-button${interview.id}').popover('#simple-popover${interview.id}', {});
                            $('#top-button').popover('#top-popover', {preventLeft:true, preventRight:true, preventBottom:true});
                        });
                    </script>
                </s:elseif>
                <s:else>
                    <a href="javascript:void(0)" value="Simple Popover" class="button"><span class="icon"
                                                                                             style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>
                            ${interview.status.name}</a>
                </s:else>
            </td>
            <td>
                <s:if test="#interview.contractStatus == null or #interview.contractStatus == 2">
                    <a href="#contract/audit_detail.xhtml?organizationId=${interview.organization.id}&employeeId=${interview.employeeId}" value="Simple Popover" class="button"><span class="icon"
                                                                                          style="background:url(${ctx}/images/img/script_error.png)">&nbsp;</span>签订合同</a>
                </s:if>
                <s:elseif test="#interview.contractStatus == 0"><a href="javascript:void(0)" value="Simple Popover"
                                                                   class="button"><span class="icon"
                                                                                        style="background:url(${ctx}/images/img/accept.png)">&nbsp;</span>审核通过</a></s:elseif>
                <s:elseif test="#interview.contractStatus == 1"><a href="javascript:void(0)" value="Simple Popover"
                                                                   class="button"><span class="icon"
                                                                                        style="background:url(${ctx}/images/img/delete.png)">&nbsp;</span>审核未通过</a></s:elseif>
                <s:else><a href="javascript:void(0)" value="Simple Popover"
                           class="button"><span class="icon"
                                                style="background:url(${ctx}/images/img/help.png)">&nbsp;</span>审核中</a></s:else>
            </td>
            </tr>
        </s:iterator>
    </s:else>
    </tbody>
</table>

<p>
    <%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp" %>
</p>

<script type="text/javascript">

    //修改员工报到状态　
    function modifyInterviewCheckState(interviewArrangeId,employeeId) {
        if (interviewArrangeId == undefined || interviewArrangeId <= 0) {
            alert("操作记录有误，请联系管理员!");
            return;
        }
        var checkinState = $("input:radio[name='checkin_rd" + interviewArrangeId + "']:checked").val();
        if (checkinState == undefined) {
            alert("请选择报到状态!");
            return;
        }
        $.ajax("${ctx}/invite/post_staffreport.xhtml", {
            type:"POST",
            data:{"interviewArrangeId":interviewArrangeId, "checkin":checkinState},
            dataType:"json",
            cache:false,
            success:function (a) {
                alert("操作成功！");
                if (checkinState == "check_in") {
                    $("#simple-popover" + interviewArrangeId).remove();                    
                   	location.href = "${ctx}/index.xhtml#employee/staff_edit.xhtml?id=" + a.workId;
                } else {
                    try {
                        loadListContent("${ctx}/invite/staff_report.xhtml",currentSelOrgId);
                        $("#simple-popover" + interviewArrangeId).remove();
                    } catch (error) {
                        //
                    }
                }
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert('提交申请发生异常');
            },
            complete:function () {
            }
        });
    }
</script>
